// 导入模块 
import { createStore } from 'vuex'

// 定义要存储的数据结构 --- 实体类
export interface State {
    count: number, 
    collapse: boolean, // 控制侧边栏是否收缩
}

// 创建一个store对象 
export const store = createStore<State>({
    // state -- 存储具体的值 
    state: {
        count: 100,
        collapse: false,
    },
    // mutations -- 修改state中的函数 
    mutations: {
        // 修改state.count
        setCount(state:State, count: number){
            state.count = count;
        },
        // 修改state.collapse 
        setCollapse(state:State, collapse: boolean){
            state.collapse = collapse;
        },
    },
    // getters --- 获取state中的值
    getters: {
        // 获取state.count值
        getCount(state:State){
            return state.count;
        },
        // 获取state.collapse的值
        getCollapse(state:State){
            return state.collapse;
        }

    }
})

// 暴露 
export default store
